<?php
	//objetos
	include "../model/Device.php";
	include "../model/Driver.php";
	include "../model/Apn.php";
	include "../model/Model.php";
	include "../model/Package.php";
	include "../model/Usuario.php";
	include "../model/Ponto.php";
	include "../model/SimCard.php";
	//DAO'S
	include "../dao/DeviceDAO.php";
	include "../dao/DriverDAO.php";
	include "../dao/ApnDAO.php";
	include "../dao/ModelDAO.php";
	include "../dao/PackageDAO.php";
	include "../dao/UsuarioDAO.php";
	include "../dao/PontoDAO.php";
	include "../dao/SimCardDAO.php";
	
	$devicedao 	 = new DeviceDAO();
	$driverdao 	 = new DriverDAO();
	$apndao 	 = new ApnDAO();
	$modeldao 	 = new ModelDAO();
	$packagedao	 = new PackageDAO();
	$usuariodao  = new UsuarioDAO();
	$pontodao	 = new PontoDAO();
	
	if(isset($_GET['idDevice']) && !isset($_GET['idPonto']) ){
	
		$device = new Device();
		
		$device->setIdDevice($_GET['idDevice']);
		$device->setIdApn($_POST['idapn']);
		$device->setIdSimCard($_POST["simcard"]);
		$device->setIdFeature($_POST['idmodel']);
		$device->setIdDriver($_POST['iddriver']);
		$device->setImei($_POST['imei']);
		
		$devicedao->update($device);
		
	}else if(isset($_GET['idDriver'])){
		
		$driver = new Driver();
		
		$driver->setIdDriver($_GET['idDriver']);
		$driver->setNome($_POST['nome']);
		$driver->setPorta($_POST['porta']);
		
		$driverdao->update($driver);
	
	}else if(isset($_GET['idApn'])){
		
		$apn = new Apn();
		
		$apn->setIdApn($_GET['idApn']);
		$apn->setApn($_POST['apn']);
		$apn->setApnUser($_POST['user']);
		$apn->setApnPass($_POST['pass']);
		
		$apndao->update($apn);
		
	}else if(isset($_GET['idModel'])){
		
		$model = new Model();
				
		$model->setIdModel($_GET['idModel']);
		$model->setModelo($_POST['modelo']);
		$model->setAplicacao($_POST['aplicacao']);
		$model->setPadrao($_POST['padrao']);
		$model->setMarca($_POST['marca']);
		$model->setWaterproof($_POST['waterproof']);
		$model->setEscuta($_POST['escuta']);
		$model->setCortaCombust($_POST['cutOil']);
		$model->setCortaEletric($_POST['cutEletric']);
		$model->setSos($_POST['sos']);
		$model->setBateria($_POST['bateria']);
		$model->setSdCard($_POST['sdCard']);
		$model->setVibracao($_POST['vibracao']);
		
		$model->setFt_alarm($_POST['ft_alarm']);
		$model->setFt_tracking($_POST['ft_tracking']);
		$model->setFt_charge($_POST['ft_charge']);
		$model->setFt_acc($_POST['ft_acc']);
		$model->setFt_voltage($_POST['ft_voltage']);
		$model->setFt_gsmsignal($_POST['ft_gsmsignal']);
		
		$modeldao->update($model);
		
	}else if(isset($_GET['idPackage'])){
		
		$package = new Package();
		
		$package->setIdPackage($_GET['idPackage']);
		$package->setTypeData($_POST['typeData']);
		$package->setIdDevice($_POST['iddevice']);
		$package->setLatitude($_POST['latitude']);
		$package->setLongitude($_POST['longitude']);
		$package->setVelocidade($_POST['velocidade']);
		$package->setDateTime($_POST['dateTime']);
		$package->setRealDateTime($_POST['realDateTime']);
		$package->setEndereco($_POST['endereco']);
		
		$package->setCombustEletric($_POST['combustEletric']);
		$package->setTracking($_POST['tracking']);
		$package->setAlarm($_POST['alarm']);
		$package->setCharge($_POST['charge']);
		$package->setVoltage($_POST['voltage']);
		$package->setAcc($_POST['acc']);
		$package->setSignal($_POST['gsmsignal']);

		$packagedao->update($package);
	
	}else if(isset($_GET['idUsuario'])){

		$usuario = new Usuario();
		
		$usuario->setIdUsuario($_GET['idUsuario']);
		$usuario->setNome($_POST['usernamesignup']);
		$usuario->setEmail($_POST['emailsignup']);
		$usuario->setCpf($_POST['cpfsignup']);
		$usuario->setNasc($_POST['nascsignup']);
		$usuario->setSexo($_POST['sexosignup']);
		$usuario->setLogin($_POST['loginsignup']);
		$usuario->setSenha($_POST['passwordsignup']);
		
		$usuariodao->update($usuario);
		
	}else if(isset($_GET['idPonto'])){
		
		$pontodao = new PontoDAO();
		
		if(isset($_GET['idDevice'])){
			
			if(isset($_GET['u'])){
				$pontodao->desconect($_GET['idPonto'], $_GET['idDevice'],1);
			}else{
				$pontodao->desconect($_GET['idPonto'], $_GET['idDevice'],null);
			}
			
		}else{
			
			$ponto = new Ponto();
			$ponto->setIdPonto($_GET['idPonto']);
			$ponto->setIdUsuario($_POST['idUsuario']);
			$ponto->setIdDevice($_POST["idDevice"]);
			$ponto->setNome($_POST["nomePonto"]);
			$ponto->setTipo($_POST["tipo"]);
			$ponto->setInfo($_POST["info"]);
					
			$pontodao->update($ponto);
			
		}
		
	}else if(isset($_GET['idSimCard'])){
		
		$simcard = new SimCard();
		
		$simcard->setIdSimCard($_GET["idSimCard"]);
		$simcard->setNumero($_POST['numero']);
		$simcard->setNumeroChip($_POST['numeroChip']);
		$simcard->setPlano($_POST['plano']);
		$simcard->setVencPlano($_POST['vencPlano']);
	
		$simcarddao = new SimCardDAO();
		$simcarddao->update($simcard);
	
	}
	
?>